package org.senseframework.support.open.api.controller;

import org.springframework.beans.factory.InitializingBean;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * Created by lanjian on 2015/6/2.
 */
public class ServiceFilter implements InitializingBean {
    public Set filter = new HashSet();

    private long time;

    public long getTime() {
        return time;
    }

    public void setTime(long time) {
        this.time = time;
    }

    public boolean isNoService(String service, String version) {
        return filter.contains(service + version);
    }

    private ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3);

    public void afterPropertiesSet() throws Exception {
        scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
//                try {
//                    filter.clear();
//                    List<NoService> list = Mongo.buildMongo().findAll(NoService.class, AiChangDBTable.NO_SERVICE);
//                    if (CollectionUtils.isNotEmpty(list)) {
//                        for (NoService noService : list) {
//                            filter.add(noService.getService() + noService.getVersion());
//                        }
//                    }
//                } catch (Exception ex) {
//
//                }
            }
        }, 5, time, TimeUnit.SECONDS);
    }
}
